// controller 里面导入 model ，调用model 的方法，查询数据库
import Performance from '../modles/performanceModelSchema';
import logger from '../logger';
import url from 'url';

interface PerformanceType {
  savePerformance: Function;
}
const PerformanceCtrl = <PerformanceType>{};

// 保存performance
PerformanceCtrl.savePerformance = (req: any, res: any, next: Function) => {
  const queryData = url.parse(req.url, true)?.query || {};
  let { performance }: any = queryData;
  performance = JSON.parse(performance);
  Performance.create({ performance: performance.performanceData }).then(
    (trace) => {
      res.send({
        success: true,
      });
    }
  );
};

export default PerformanceCtrl;
